# Copyright (c) 2024, json_wang and contributors
# For license information, please see license.txt

import frappe
from frappe.model.document import Document
from frappe.utils import now_datetime,nowdate


class indicator_template(Document):
	@frappe.whitelist()
	def send_out(self, throw_if_missing=False):		
		for dept in self.tbbm:
			doc = frappe.new_doc('indicator_submit')			
			doc.tbrq = nowdate()
			doc.tbbm = dept
			doc.bbnf = "2024"
			doc.bbzq = "04"			
			doc.from_template = self.name
			for item in self.zbmx:
				doc.append("zbmx", {
    				"zbbm": item.zbbm,
    				"zbmc": item.zbmc,
					"zbdw": item.zbdw  
				})
			doc.save(ignore_permissions=True, # ignore write permissions during insert
			    ignore_version=True # do not create a version record
				)
		return "填报模板下发成功!"